122 research outputs found

    Comparing Tag Scheme Variations Using an Abstract Machine Generator

    Get PDF
    In this paper we study, in the context of a WAM-based abstract machine for Prolog, how variations in the encoding of type information in tagged words and in their associated basic operations impact performance and memory usage. We use a high-level language to specify encodings and the associated operations. An automatic generator constructs both the abstract machine using this encoding and the associated Prolog-to-byte code compiler. Annotations in this language make it possible to impose constraints on the final representation of tagged words, such as the effectively addressable space (fixing, for example, the word size of the target processor /architecture), the layout of the tag and value bits inside the tagged word, and how the basic operations are implemented. We evaluate large number of combinations of the different parameters in two scenarios: a) trying to obtain an optimal general-purpose abstract machine and b) automatically generating a specially-tuned abstract machine for a particular program. We conclude that we are able to automatically generate code featuring all the optimizations present in a hand-written, highly-optimized abstract machine and we canal so obtain emulators with larger addressable space and better performance

    An automatic documentation generator for (C)LP - Reference manual

    Full text link
    Lpdoc is an automatic program documentation generator for (C)LP systems. Lpdoc generates a reference manual automatically from one or more source files for a logic program (including ISO-Prolog, Ciao, many CLP systems, ...). It is particularly useful for documenting library modules, for which it automatically generates a description of the module interface. However, lpdoc can also be used quite successfully to document full applications and to generate nicely formatted plain ascii "readme" files. A fundamental advantage of using lpdoc to document programs is that it is much easier to maintain a true correspondence between the program and its documentation, and to identify precisely to what version of the program a given printed manual corresponds. The quality of the documentation generated can be greatly enhanced by including within the program text: • assertions (types, modes, etc. ...) for the predicates in the program, and • machine-readable comments (in the "literate programming" style). The assertions and comments included in the source file need to be written using the Ciao system assertion language. A simple compatibility library is available to make traditional (constraint) logic programming systems ignore these assertions and comments allowing normal treatment of programs documented in this way. The documentation is currently generated in HTML or texinf o format. From the texinf o output, printed and on-line manuals in several formats (dvi, ps, info, etc.) can be easily generated automatically, using publicly available tools, lpdoc can also generate 'man' pages (Unix man page format) as well as brief descriptions in html or emacs info formats suitable for inclusion in an on-line index of applications. In particular, lpdoc can create and maintain fully automatically WWW and info sites containing on-line versions of the documents it produces. The lpdoc manual (and the Ciao system manuals) are generated by lpdoc. Lpdoc is distributed under the GNU general public license. Note: lpdoc is fully supported on Linux, Mac OS X, and other Un*x-like systems. Due to the use of several Un*x-related utilities, some documentation back-ends may require Cygwin under Win32. This documentation corresponds to version 3.0 (2011/7/7, 16:33:15 CEST)

    Advanced Compilation Techniques for Logic Programming = Técnicas Avanzadas de Compilación para Programación Lógica

    Full text link
    Declarative programming languages allow the expression of programs in a language that is closer to the problem than to the implementation details. Regardless the generality of that definition, a more clear idea of declarativeness is proposed by Lloyd[Llo94], who proposes that programs are theories in some suitable logic, and computation is deduction from the theory. In logic programming, where Prolog is one of the most popular incarnations of that paradigm, the theory is that of logical deduction. Efficient implementations able to compete with many other high-level languages, and its flexibility, made Prolog a very good framework to develop new ideas, such as constraint programming, and multi-paradigm programming merging functional programming, object oriented programming, and imperative programming. Although the state of the art of Prolog implementations is highly optimized for the kind of search problems it is designed, and it can compete with many language implementations for other paradigms — both logic, functional, and imperative — its dynamism and declarative nature imposes a considerable efficiency gap. An ambitious goal for Prolog implementations, shared with many other declarative languages, is closing this gap while not sacrificing expressivity. The objective of this thesis is the development and improvement of advanced techniques for compilation of Prolog, orthogonal to many extensions such as constraint logic programming [JM87], Prolog with tabling [War92], CHR over Prolog [SF08]. The main contributions presented in this thesis can be summarized as: An optimizing compiler of Prolog, where selected predicates can be compiled to C, and designed to accept high-level information, obtained from automatic analysis, and expressed in a standardized language of assertions. An automatic approach to the generation of abstract machines, where the instruction set, and the bytecode and data representation can be defined individually. Description of the full instruction set of a Prolog abstract machine in a Prolog dialect extended with state-changes (as mutable variables), amenable to program transformations. Representation of tagged words in the higher-level language, exploring many alternatives for the 32 and 64 bit cases. A parametric framework to generate variations of abstract machines, to explore optimizations in general or targeting a particular set of programs. Study of the combination of the source-level and low-level optimization compilation techniques in a real test case for embedded devices. Los lenguajes de programación declarativos permiten expresar programas en un lenguaje que es más cercano al problema que a los detalles de implementación. A pesar de la genericidad de esta definición, Lloyd propone una noción más clara de la declaratividad [Llo94], definiendo los programas como teorías en una lógica adecuada y la computación deducción en base a la teoría. Prolog es uno de los lenguajes de programación del paradigma lógico más importantes, cuya teoría es la de la deducción lógica. Implementaciones eficientes capaces de competir con muchos otros lenguajes de alto nivel y su flexibilidad, han hecho de Prolog un importante punto de partida para desarrollar nuevas ideas, como la programación con restricciones y multi-paradigma, mezclando programación funcional, orientada a objetos e imperativa. Aunque el estado del arte de las implementaciones de Prolog esta altamente optimizado para el tipo de problemas de busqueda para los que este está diseñado y que puede competir con muchas implementaciones de otros paradigmas — tanto lógico, funcional, como imperativo — su naturaleza caracteristicas dinámicas y declarativas imponen una considerable limitación en eficiencia. Un ambicioso objetivo para las implementaciones de Prolog, compartido por muchos otros lenguajes declarativos, consiste en el desarrollo de téctnicas que superen esta limitación sin sacrificar la expresividad del lenguaje. El objetivo de esta tesis es el desarrollo y mejora de técnicas avanzadas de compilacion para Prolog, en principio ortogonales a extensiones como la programación lógica con restricciones [JM87], Prolog con tabulación [War92] o CHR sobre Prolog [SF08]. Las principales contribuciones presentadas en esta tesis pueden resumirse en: Un compilador optimizante de Prolog, donde predicados seleccionados son compilados a C y diseñado para aceptar información de alto nivel, obtenida mediante análisis automático y expresada en un lenguaje estandarizado de aserciones. Un enfoce automático a la generación de máquinas abstractas, donde el conjunto de instrucciones y la representación de código de byte y datos son definidas de forma individual. Una descripción del conjunto de instrucciones completo de una máquina abstract para Prolog, en un dialecto de Prolog extendido para manejar cambios de estado (en forma de variables mutables) y adecuado para realizar transformaciones automáticas de programa. Una representación de tagged words (palabras con etiquetas) en un lenguaje de alto nivel, explorando variantes para los casos de 32 y 64 bit. Un marco de trabajo paramétrico para la generación de variaciones de máquinas abstractas, para explorar optimizaciones de forma general o enfocadas a un conjunto particular de programas. Un estudio de la combinación de técnicas de compilación optimizante en código fuente y en código de bajo nivel, en un caso de prueba real para sistemas ubícuos

    The Ciao clp(FD) library. A modular CLP extension for Prolog

    Get PDF
    We present a new free library for Constraint Logic Programming over Finite Domains, included with the Ciao Prolog system. The library is entirely written in Prolog, leveraging on Ciao's module system and code transformation capabilities in order to achieve a highly modular design without compromising performance. We describe the interface, implementation, and design rationale of each modular component. The library meets several design goals: a high level of modularity, allowing the individual components to be replaced by different versions; highefficiency, being competitive with other TT> implementations; a glass-box approach, so the user can specify new constraints at different levels; and a Prolog implementation, in order to ease the integration with Ciao's code analysis components. The core is built upon two small libraries which implement integer ranges and closures. On top of that, a finite domain variable datatype is defined, taking care of constraint reexecution depending on range changes. These three libraries form what we call the TT> kernel of the library. This TT> kernel is used in turn to implement several higher-level finite domain constraints, specified using indexicals. Together with a labeling module this layer forms what we name the TT> solver. A final level integrates the CLP (J7©) paradigm with our TT> solver. This is achieved using attributed variables and a compiler from the CLP (J7©) language to the set of constraints provided by the solver. It should be noted that the user of the library is encouraged to work in any of those levels as seen convenient: from writing a new range module to enriching the set of TT> constraints by writing new indexicals

    Towards modular extensions for a modular language

    Get PDF
    Modularity allows the construction of complex designs from simpler, independent units that most of the time can be developed separately. In this paper we are concerned with developing mechanisms for easily implementing modular extensions to modular (logic) languages. By (language) extensions we refer to different groups of syntactic definitions and translation rules that extend a language. Our application of the concept of modularity in this context is twofold. We would like these extensions to be modular, in the above sense, i.e., we should be able to develop different extensions mostly separately. At the same time, the sources and targets for the extensions are modular languages, i.e., such extensions may take as input separate pieces of code and also produce separate pieces of code. Dealing with this double requirement involves interesting challenges to ensure that modularity is not broken: first, combinations of extensions (as if they were a single extension) must be given a precise meaning. Also, the separate translation of multiple sources (as if they were a single source) must be feasible. We present a detailed description of a code expansion-based framework that proposes novel solutions for these problems. We argue that the approach, while implemented for Ciao, can be adapted for other languages and Prolog-based systems

    Reversible language extensions and their application in debugging

    Get PDF
    A range of methodologies and techniques are available to guide the design and implementation of language extensions and domainspecific languages. A simple yet powerful technique is based on source-tosource transformations interleaved across the compilation passes of a base language. Despite being a successful approach, it has the main drawback that the input source code is lost in the process. When considering the whole workflow of program development (warning and error reporting, debugging, or even program analysis), program translations are no more powerful than a glorified macro language. In this paper, we propose an augmented approach to language extensions for Prolog, where symbolic annotations are included in the target program. These annotations allow selectively reversing the translated code. We illustrate the approach by showing that coupling it with minimal extensions to a generic Prolog debugger allows us to provide users with a familiar, source-level view during the debugging of programs which use a variety of language extensions, such as functional notation, DCGs, or CLP{Q,R}

    Towards description and optimization of abstract machines in an extension of prolog

    Get PDF
    Competitive abstract machines for Prolog are usually large, intricate, and incorpórate sophisticated optimizations. This makes them difñcult to code, optimize, and, especially, maintain and extend. This is partly due to the fact that efñciency considerations make it necessary to use low-level languages in their implementation. Writing the abstract machine (and ancillary code) in a higher-level language can help harness this inherent complexity. In this paper we show how the semantics of basic components of an efficient virtual machine for Prolog can be described using (a variant of) Prolog which retains much of its semantics. These descriptions are then compiled to C and assembled to build a complete bytecode emulator. Thanks to the high level of the language used and its closeness to Prolog the abstract machine descriptions can be manipulated using standard Prolog compilation and optimization techniques with relative ease. We also show how, by applying program transformations selectively, we obtain abstract machine implementations whose performance can match and even exceed that of highly-tuned, hand-crafted emulators

    Improving the compilation of prolog to C using type and determinism information: Preliminary results

    Full text link
    We describe the current status of and provide preliminary performance results for a compiler of Prolog to C. The compiler is novel in that it is designed to accept different kinds of high-level information (typically obtained via an analysis of the initial Prolog program and expressed in a standardized language of assertions) and use this information to optimize the resulting C code, which is then further processed by an off-the-shelf C compiler. The basic translation process used essentially mimics an unfolding of a C-coded bytecode emúlator with respect to the particular bytecode corresponding to the Prolog program. Optimizations are then applied to this unfolded program. This is facilitated by a more flexible design of the bytecode instructions and their lower-level components. This approach allows reusing a sizable amount of the machinery of the bytecode emulator: ancillary pieces of C code, data definitions, memory management routines and áreas, etc., as well as mixing bytecode emulated code with natively compiled code in a relatively straightforward way We report on the performance of programs compiled by the current versión of the system, both with and without analysis information

    Towards structured state threading in prolog

    Get PDF
    It is very often the case that programs require passing, maintaining, and updating some notion of state. Prolog programs often implement such stateful computations by carrying this state in predicate arguments (or, alternatively, in the internal datábase). This often causes code obfuscation, complicates code reuse, introduces dependencies on the data model, and is prone to incorrect propagation of the state information among predicate calis. To partly solve these problems, we introduce contexts as a consistent mechanism for specifying implicit arguments and its threading in clause goals. We propose a notation and an interpretation for contexts, ranging from single goals to complete programs, give an intuitive semantics, and describe a translation into standard Prolog. We also discuss a particular light-weight implementation in Ciao Prolog, and we show the usefulness of our proposals on a series of examples and applications, including code directiy using contexts, DCGs, extended DCGs, logical loops and other custom control structures
    corecore